package com.sping_boot3.spirng_boot3.handler;

import com.sping_boot3.spirng_boot3.entity.User;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.web.servlet.function.ServerRequest;
import org.springframework.web.servlet.function.ServerResponse;

import java.util.Arrays;
import java.util.List;

@Service
@Slf4j
public class UserHandler {

    public ServerResponse getUserById(ServerRequest request){
        String id = request.pathVariable("id");
        User user = new User();
       return ServerResponse.ok().body(user);
    }

    public ServerResponse getUserList(ServerRequest request) {
        List<User> list = Arrays.asList(new User(), new User());
        return ServerResponse.ok().body(list);
    }

    @SneakyThrows
    public ServerResponse addUser(ServerRequest request) {
        User body = request.body(User.class);
        log.info("新增用户成功：{}", body);
        return ServerResponse.ok().build();
    }

    public ServerResponse delUser(ServerRequest request) {
        String id = request.param("id").orElse("");
        log.info("删除【{}】用户信息", id);
        return ServerResponse.ok().build();
    }
}
